package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;

import com.seanchenxi.gwt.wordpress.domain.model.CommentCount;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class CommentCountsResponseHandler extends BaseResponseHandler<ArrayList<CommentCount>>{
	
	@Override
	public ArrayList<CommentCount> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<CommentCount> commentCounts = new ArrayList<CommentCount>();
		for(Object obj : (ArrayList<?>)object){
			CommentCount commentCount = ModelFactory.ToCommentCount(obj);
			if(commentCount!=null && !commentCounts.contains(commentCount)){ 
				commentCounts.add(commentCount);
			}
		}
			
		return commentCounts;
	}
	
}
